home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_02_09 / 2n09006a < prev    next >
Text File  |  1991-07-24  |  7KB  |  162 lines

  1.  
  2. /* test from to show use of MultiLine Edit Controls using */
  3. /* RETURN and TAB  */
  4. #include "windows.h"
  5. #include "mledit.h"
  6.  
  7. HANDLE hInst=NULL;
  8. HWND hDlgModeless=NULL;
  9.  
  10. /* functions */
  11. BOOL InitApplication(HANDLE hInstance);
  12. BOOL InitInstance(HANDLE hInstance, int nCmdShow);
  13. long FAR PASCAL MainWndProc( HWND hWnd, unsigned message, WORD wParam, LONG lParam);
  14. BOOL FAR PASCAL TestDlg ( HWND hDlg, unsigned message, WORD wParam, LONG lParam);
  15. BOOL InitMLE(HWND hDialogWnd, int EditId);
  16. long FAR PASCAL EditWndProc(HWND hWnd, unsigned message, WORD wParam, LONG lParam);
  17. /* test code to demonstrate the Multiline edit control code */
  18. int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  19. HANDLE hInstance;                            /* current instance             */
  20. HANDLE hPrevInstance;                        /* previous instance            */
  21. LPSTR lpCmdLine;                             /* command line                 */
  22. int nCmdShow;                                /* show-window type (open/icon) */
  23. {
  24.     MSG msg;                                 /* message                      */
  25.  
  26.  
  27.     if (!hPrevInstance)                  /* Other instances of app running? */
  28.     {
  29.                 if (!InitApplication(hInstance)) /* Initialize shared things */
  30.                     return (FALSE);              /* Exits if unable to initialize     */
  31.         }
  32.     /* Perform initializations that apply to a specific instance */
  33.  
  34.     if (!InitInstance(hInstance, nCmdShow))
  35.         return (FALSE);
  36.  
  37.     /* Acquire and dispatch messages until a WM_QUIT message is received. */
  38.  
  39.     while (GetMessage(&msg,        /* message structure                      */
  40.             NULL,                  /* handle of window receiving the message */
  41.             NULL,                  /* lowest message to examine              */
  42.             NULL))                 /* highest message to examine             */
  43.         {
  44.                 if (!hDlgModeless || !IsDialogMessage(hDlgModeless, &msg))
  45.                 {
  46.                         TranslateMessage(&msg);    /* Translates virtual key codes           */
  47.                         DispatchMessage(&msg);     /* Dispatches message to window           */
  48.                 }
  49.     }
  50.  
  51.     return (msg.wParam);           /* Returns the value from PostQuitMessage */
  52. }
  53.  
  54. BOOL InitApplication(hInstance)
  55. HANDLE hInstance;                              /* current instance           */
  56. {
  57.     WNDCLASS  wc;
  58.  
  59.     /* Fill in window class structure with parameters that describe the       */
  60.     /* main window.                                                           */
  61.  
  62.     wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;                    /* Class style(s).                    */
  63.     wc.lpfnWndProc = MainWndProc;       /* Function to retrieve messages for  */
  64.                                         /* windows of this class.             */
  65.     wc.cbClsExtra = 0;                  /* No per-class extra data.           */
  66.     wc.cbWndExtra = 0;                  /* No per-window extra data.          */
  67.     wc.hInstance = hInstance;           /* Application that owns the class.   */
  68.     wc.hIcon = NULL;
  69.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  70.     wc.hbrBackground = GetStockObject(WHITE_BRUSH); 
  71.     wc.lpszMenuName =  NULL;   /* Name of menu resource in .RC file. */
  72.     wc.lpszClassName = "AppClass"; /* Name used in call to CreateWindow. */
  73.         if (!RegisterClass(&wc))
  74.                 return(FALSE);
  75.         return(TRUE);
  76. }
  77.  
  78.  
  79. BOOL InitInstance(hInstance, nCmdShow)
  80.     HANDLE          hInstance;          /* Current instance identifier.       */
  81.     int             nCmdShow;           /* Param for first ShowWindow() call. */
  82. {
  83.         HWND hMainWnd;
  84.  
  85.     /* Save the instance handle in static variable, which will be used in  */
  86.     /* many subsequence calls from this application to Windows.            */
  87.  
  88.     hInst = hInstance;
  89.         
  90.         hMainWnd = CreateWindow(
  91.             "AppClass",                /* See RegisterClass() call.          */
  92.                 "Test",                                         /* Text for window title bar.         */
  93.                 WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,            /* Window style.                      */
  94.                         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  95.             NULL,                           /* Overlapped windows have no parent. */
  96.             NULL,                           /* Use the window class menu.         */
  97.             hInstance,                      /* This instance owns this window.    */
  98.             NULL                            /* Pointer not needed.                */
  99.         );
  100.  
  101.     /* If window could not be created, return "failure" */
  102.  
  103.     if (!hMainWnd)
  104.         return (FALSE);
  105.  
  106.     /* Make the window visible; update its client area; and return "success" */
  107.  
  108.     ShowWindow(hMainWnd, nCmdShow);  /* Show the window                        */
  109.     UpdateWindow(hMainWnd);          /* Sends WM_PAINT message                 */
  110.  
  111. /* make another modeless dialog box to show the Multiline edit control in */
  112.         hDlgModeless = CreateDialog(hInst, "MLEditBox", hMainWnd, MakeProcInstance(TestDlg, hInst));
  113.  
  114.     return (TRUE);
  115.  
  116. }
  117.  
  118. /* main wnd proc - does nothing at all!!! except process WM_DESTROY */
  119. long FAR PASCAL MainWndProc( HWND hWnd, unsigned message, WORD wParam, LONG lParam)
  120. {
  121.         switch(message)
  122.         {
  123.                 case WM_DESTROY:
  124.                         PostQuitMessage(0);
  125.                         return(0);
  126.                         break;
  127.         }
  128.         return DefWindowProc ( hWnd, message, wParam, lParam);
  129. }
  130.  
  131. /* dialog box WndProc - only sets up the ML Edit */
  132. BOOL FAR PASCAL TestDlg ( HWND hDlg, unsigned message, WORD wParam, LONG lParam)
  133. {
  134.         switch(message)
  135.         {
  136.                 case WM_INITDIALOG:
  137.         /* call InitMLE for each Multiline edit control within your dialog box */
  138.                         InitMLE(hDlg, IDC_MLEDIT);      /* setup the edit control */
  139.                                 /* set focus to it */
  140.                         SetFocus(GetDlgItem(hDlg, IDC_MLEDIT));
  141.                         return(FALSE);  /* cause we set focus */
  142.                         break;
  143.                 
  144.                 case WM_COMMAND:
  145.                         switch(wParam)
  146.                         {
  147.                                 case IDOK:
  148.                                         PostMessage(GetParent(hDlg), WM_CLOSE, 0, 0L);  /* and therefore for parent */
  149.                                         DestroyWindow(hDlg);    /* done for dialog box */
  150.                                         hDlgModeless = NULL;
  151.                                         return(TRUE);
  152.                                         break;
  153.  
  154.                                 default:
  155.                                         return(FALSE);
  156.                         }
  157.         }
  158.  
  159.         return(FALSE);          /* no message processed */
  160. }
  161.  
  162.